package com.zzyl.controller;


import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ResourceDto;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.ResourceVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/resource")
@Api(tags ="资源管理")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;

    //资源列表
    @PostMapping("/list")
    @ApiOperation(value = "资源列表")
    public ResponseResult<ResourceVo> getResourceList(@RequestBody ResourceDto resourceDto){

        List<ResourceVo> resourceVoList = resourceService.getResourceList(resourceDto);
        return ResponseResult.success(resourceVoList);
    }

    //资源树
    @PostMapping("/tree")
    @ApiOperation(value = "资源树")
    public ResponseResult<TreeVo> resourceTreeVo(@RequestBody ResourceDto resourceDto){
        TreeVo treeVo = resourceService.getresourceTreeVo(resourceDto);
        return ResponseResult.success(treeVo);
    }

    //资源添加
    @PutMapping
    @ApiOperation(value = "资源添加")
    public ResponseResult addresource(@RequestBody ResourceDto resourceDto){
        resourceService.addresource(resourceDto);
        return ResponseResult.success(true);
    }

    //资源修改
    @PatchMapping
    @ApiOperation(value = "资源修改")
    public ResponseResult updateResource(@RequestBody ResourceDto resourceDto){
        resourceService.updateResource(resourceDto);
        return ResponseResult.success(true);
    }

    //资源启用禁用

    @PostMapping("/enable")
    @ApiOperation(value = "资源启用禁用")
    public ResponseResult isEnable(@RequestBody ResourceDto resourceDto){
        resourceService.isEnable(resourceDto);
        return ResponseResult.success(true);
    }

    @DeleteMapping("/{resourceNo}")
    @ApiOperation(value = "资源删除")
    public ResponseResult deleteResource(@PathVariable String resourceNo){
        resourceService.deleteResource(resourceNo);
        return ResponseResult.success();
    }
}
